package com.ruoyi.project.jiaqin.question.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.question.domain.JiaqinQuestion;
import com.ruoyi.project.jiaqin.question.service.IJiaqinQuestionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 问题Controller
 * 
 * @author admin
 * @date 2020-12-30
 */
@Controller
@RequestMapping("/jiaqin/question")
public class JiaqinQuestionController extends BaseController
{
    private String prefix = "jiaqin/question";

    @Autowired
    private IJiaqinQuestionService jiaqinQuestionService;

    @RequiresPermissions("jiaqin:question:view")
    @GetMapping()
    public String question()
    {
        return prefix + "/question";
    }

    /**
     * 查询问题列表
     */
    @RequiresPermissions("jiaqin:question:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinQuestion jiaqinQuestion)
    {
        startPage();
        List<JiaqinQuestion> list = jiaqinQuestionService.selectJiaqinQuestionList(jiaqinQuestion);
        return getDataTable(list);
    }

    /**
     * 导出问题列表
     */
    @RequiresPermissions("jiaqin:question:export")
    @Log(title = "问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinQuestion jiaqinQuestion)
    {
        List<JiaqinQuestion> list = jiaqinQuestionService.selectJiaqinQuestionList(jiaqinQuestion);
        ExcelUtil<JiaqinQuestion> util = new ExcelUtil<JiaqinQuestion>(JiaqinQuestion.class);
        return util.exportExcel(list, "question");
    }

    /**
     * 新增问题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存问题
     */
    @RequiresPermissions("jiaqin:question:add")
    @Log(title = "问题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinQuestion jiaqinQuestion)
    {
        return toAjax(jiaqinQuestionService.insertJiaqinQuestion(jiaqinQuestion));
    }

    /**
     * 修改问题
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinQuestion jiaqinQuestion = jiaqinQuestionService.selectJiaqinQuestionById(id);
        mmap.put("jiaqinQuestion", jiaqinQuestion);
        return prefix + "/edit";
    }

    /**
     * 修改保存问题
     */
    @RequiresPermissions("jiaqin:question:edit")
    @Log(title = "问题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinQuestion jiaqinQuestion)
    {
        return toAjax(jiaqinQuestionService.updateJiaqinQuestion(jiaqinQuestion));
    }

    /**
     * 删除问题
     */
    @RequiresPermissions("jiaqin:question:remove")
    @Log(title = "问题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinQuestionService.deleteJiaqinQuestionByIds(ids));
    }
}
